package com.dat255.internalstorage;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * This class will assist the database to create
 * tables with appropriate columns for an exam
 * object 
 * @author Joseph
 *
 */
public class DbHelper extends SQLiteOpenHelper {

	private static final int DATABASE_VERSION = 1;
	private static final String DATABASE_NAME = "exams.db";
	private static String TABLE_NAME = "favorites";
	private static final String COL_COURSE_NAME = "course_name";
	private static final String COL_COURSE_ID = "course_id";
	private static final String COL_COURSE_TIME = "time_exam";
	private static final String COL_COURSE_DATE = "date_exam";
	private static final String COL_COURSE_PLACE = "place_exam";
	
	//The SQL command to creata a table on the database
	private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_NAME + " ( " +
			COL_COURSE_ID + " TEXT UNIQUE, " +
			COL_COURSE_NAME + " TEXT, " +
			COL_COURSE_TIME + " TEXT, " +
			COL_COURSE_DATE + " TEXT, " +
			COL_COURSE_PLACE  + " TEXT);";
			
	/**
	 * Default constructor		
	 * @param application context
	 */
	public DbHelper(Context context) {
		super(context, DATABASE_NAME, null,  DATABASE_VERSION);

	}
	/**
	 * Second constructor for diffrent table name
	 * @param context
	 * @param Name of the table
	 */
	public DbHelper(Context context, String table_name) {
		super(context, DATABASE_NAME, null,  DATABASE_VERSION);
		TABLE_NAME = table_name;
		
	}
	
	/**
	 * Creates a new table on the database
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		
		
		db.execSQL(DATABASE_CREATE);
		
		
	}

	/**
	 * On upgrade of the database, the old table is removed(if it exists) and a
	 * new table is created
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	
		db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME );
		//call the oncreate method to create a new table
		this.onCreate(db);

	}
	/**
	 * Returns the name of the database
	 * @return name of the table
	 */
	public static String getDatabaseName() {
		return DATABASE_NAME;
	}
	/**
	 * Returns the name of the table
	 * @return name of the table
	 */
	public static String getExamlistTableName() {
		return TABLE_NAME;
	}
	/**
	 * Returns the name of the course name column
	 * @return column name for course id
	 */
	public static String getColCourseName() {
		return COL_COURSE_NAME;
	}
	/**
	 *  Returns the course id column name
	 * @return course id column name
	 */
	public static String getColCourseId() {
		return COL_COURSE_ID;
	}
	/**
	 *  Return the column name of the exam time
	 * @return column name of the exam time
	 */
	public static String getColCourseTime() {
		return COL_COURSE_TIME;
	}
	/** 
	 * Returns the column name of the exam date
	 * @return column name of date
	 */
	public static String getColCourseDate() {
		return COL_COURSE_DATE;
	}
	/**
	 * Returns the column name of the exam place
	 * @return column name of the exam place
	 */
	public static String getColCoursePlace() {
		return COL_COURSE_PLACE;
	}

	
}
